package cn.haut.online_read.controller.crawler.zhuishushenqi;

import cn.haut.online_read.crawler.BookChapterContentCrawler;
import cn.haut.online_read.crawler.BookCrawler;
import cn.haut.online_read.utils.CrawlerUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author xing
 * @date 2021-04-21 13:21
 */
@Controller("bookContentController")
@RequestMapping(value = "/book")
@Slf4j
public class BookContentController {

    public static final String BASE_URL_CONTENT = "http://zhuishushenqi.com/book";

    @GetMapping(value = {"/{bookId}"})
    @ResponseBody
    public String getBookContent (@PathVariable("bookId") String bookId) {
        String url = BASE_URL_CONTENT + "/" + bookId;
        return CrawlerUtils.getJsonResult(new BookCrawler(), url);
    }

    @GetMapping(value = {"/{bookId}/{chapterNum}"})
    @ResponseBody
    public String getChapterContent(
            @PathVariable("bookId") String bookId,
            @PathVariable("chapterNum") String chapterNum
    ){
        String url = BASE_URL_CONTENT + "/" + bookId + "/" + chapterNum + ".html";
        return CrawlerUtils.getJsonResult(new BookChapterContentCrawler(), url);
    }
}
